<?php 
require_once("../includes/config.php"); 

if($_SERVER["REQUEST_METHOD"] == "POST"){
      $sql= query("INSERT INTO unit_type (type_name , owner_id) VALUES (?,?)",$_POST['type_name'] ,$_SESSION['user_id']);

	   $_SESSION['success_message'] = "تم اضافة النوع بنجاح"; 
	   
	    $units_type=query("SELECT * FROM unit_type");
	    redirect("apartments_type.php");
      }  
	 //editing
	 if(isset($_GET['edit_name'])&& isset($_GET['id'])){
	  $sql= query("UPDATE unit_type SET type_name=? WHERE type_id=? and owner_id = ?",$_GET['edit_name'],$_GET['id'],$_SESSION['user_id']);
	    $_SESSION['success_message'] = "تم تعديل النوع بنجاح"; 
	  $units_type=query("SELECT * FROM unit_type");
	  redirect("apartments_type.php");
	  } 
	  
  $units_type=query("SELECT * FROM unit_type WHERE owner_id = ?",$_SESSION['user_id']);
 
render("/settings/apartments-type.php", array("title"=>"ادارة انواع الوحدات","units_type"=>$units_type));
?>